package com.dlut.java4;

import java.util.Scanner;

/**
 * @Author: LiuHeng
 * @Description:
 * @Date: 2022-09-18 11:15
 */
public class T0918_ZiJie4 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        STree maxtree = new STree(arr, Math::max);
        STree mintree = new STree(arr, Math::min);
        int len = 0;
        int left = 0, right = 5;
        /*
        while (left <= right && right < n){
            int max = maxtree.query(left, right);
            int min = mintree.query(left, right);
            if (max - min <= k){
                right++;
            }else {
                len = Math.max(len, right- left);
                left++;
            }
        }
        len = Math.max(len, right- left);
        System.out.println(len);
        */
        for (int i = 0; i < n - 3; i++) {
            int max = maxtree.query(i, i+3);
            int min = mintree.query(i, i+3);
            System.out.println(max+ " " +min);
        }
    }


    static class STree{
        private int[] data;
        private int[] tree;
        private Merger merger;
        public STree(int[] arr, Merger merger){
            this.merger = merger;
            data = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {
                data[i] = arr[i];
            }
            tree = new int[arr.length * 3];
            buildSeg(0, 0, data.length-1);
        }

        private void buildSeg(int index, int l, int r) {
            if (l == r){
                tree[index] = data[l];
                return;
            }
            int left = 2 * index + 1;
            int right = 2 * index + 2;
            int mid = (l + r) / 2;
            buildSeg(left, l, mid);
            buildSeg(right, mid+ 1, r);
            tree[index] = merger.merger(tree[left], tree[right]);
        }
        public int query(int queryL, int queryR){
            if (queryL < 0 || queryR >= data.length || queryL > queryR){
                throw new RuntimeException("错误");
            }
            return queryRange(0, 0, data.length - 1, queryL, queryR);
        }

        private int queryRange(int index, int l, int r, int queryL, int queryR) {
            int result = 0;
            if (queryL == l &&queryR == r){
                return tree[index];
            }
            int left = 2 * index + 1;
            int right = 2 * index + 2;
            int mid = (l + r) / 2;
            if (queryL >= mid + 1){
                result = queryRange(right, mid + 1, r, queryL, queryR);
            }else if (queryR <= mid){
                result = queryRange(left, l, mid, queryL, queryR);
            }else {
                int a = queryRange(left, l, mid, queryL, mid);
                int b = queryRange(right, mid + 1, r, mid+1, queryR);
                result = merger.merger(a,b);
            }
            return result;
        }
    }

    interface Merger {
        int merger(int a, int b);
    }
}
